import Vue from 'vue'
import Router from 'vue-router'
import { formatRoutes } from '@/utils/routerUtil'
import basicOptions from './basic'
import { mergeI18nFromRoutes } from '@/utils/i18n'
Vue.use(Router)

// 不需要登录拦截的路由配置
const loginIgnore = {
  names: ['exp404', 'exp403'], // 根据路由名称匹配
  paths: ['/login', '/loginsso'], // 根据路由fullPath匹配
  /**
   * 判断路由是否包含在该配置中
   * @param route vue-router 的 route 对象
   * @returns {boolean}
   */
  includes(route) {
    return this.names.includes(route.name) || this.paths.includes(route.path)
  }
}

/**
 * 初始化路由实例
 * @returns {VueRouter}
 */
function initRouter({ i18n }) {
  formatRoutes(basicOptions.routes)
  mergeI18nFromRoutes(i18n, basicOptions.routes)
  return new Router({
    ...basicOptions,
    mode: 'history'
  })
}
export { loginIgnore, initRouter }
